<template>
	<div class="titleBar">
		<uni-data-select :localdata="days" @change="getServerData" v-model="curDate" placeholder="请选择日期" class="selectDate"></uni-data-select>
	</div>
	<div class="label-box">
		<view class="charts-box">
		  <qiun-data-charts 
		    type="line"
		    :opts="opts"
		    :chartData="chartData"
			:ontouch="true"
		  />
		</view>
	</div>
</template>

<script>
export default {
  data() {
    return {
      chartData: {},
	  days: [
	  		  {text: '2023-12-01', value: '20231201'},
	  		  {text: '2023-12-02', value: '20231202'}],
	  curDate: '20231201',
      //您可以通过修改 config-ucharts.js 文件中下标为 ['line'] 的节点来配置全局默认参数，如都是默认参数，此处可以不传 opts 。实际应用过程中 opts 只需传入与全局默认参数中不一致的【某一个属性】即可实现同类型的图表显示不同的样式，达到页面简洁的需求。
      opts: {
        color: ["#1890FF","#91CB74","#FAC858","#EE6666","#9A60B4","#3CA272","#FC8452","#73C0DE","#ea7ccc"],
        padding: [15,10,0,15],
        enableScroll: true,
		fontSize: 8,
        legend: {},
        xAxis: {
          disableGrid: true,
		  fontSize: 8,
		  scrollShow: true,
		  itemCount: 20
        },
        yAxis: {
          gridType: "dash",
        },
		 extra: {
		  line: {
			type: "curve",
			width: 1,
			activeType: "hollow"
		  }
		}
      }
    };
  },
  onReady() {
	plus.screen.lockOrientation('landscape-primary'); // 强制横屏
	//plus.screen.lockOrientation('portrait-primary'); // 强制竖屏
    this.getServerData();
  },
  methods: {
    getServerData() {
      //模拟从服务器获取数据时的延时
      setTimeout(() => {
        //模拟服务器返回数据，如果数据格式和标准格式不同，需自行按下面的格式拼接
        let res = {
            categories: ["07:45","07:46","07:47","07:48","07:49","07:50","07:51","07:52","07:53","07:54","07:55","07:56","07:57","07:58","07:59","08:00","08:01","08:02","08:03","08:04","08:05","08:06","08:07","08:08","08:09","08:10","08:11","08:12","08:13","08:14","08:15","08:16","08:17","08:18","08:19","08:20","08:21","08:22","08:23","08:24","08:25","08:26","08:27","08:28","08:29","08:30"],
            series: [
              {
                name: "速度最快",
                data: [47,50,51,52,51,52,50,47,44,47,47,48,47,49,47,48,46,47,47,46,48,49,47,48,46,50,49,46,46,47,47,47,49,50,45,46,45,45,45,46,46,46,45,46,44,43]
              },
			  {
			    name: "距离最短",
			    data: [50,54,55,56,52,52,50,51,49,51,50,51,50,53,51,52,49,49,49,51,51,52,52,54,50,51,50,50,50,50,50,51,51,52,48,48,47,48,48,48,48,47,45,46,44,43],
			  },
			  {
				name: "高速优先",
				data: [47,50,51,52,53,54,52,47,44,47,47,48,47,49,47,48,46,47,47,46,48,49,47,48,46,46,46,47,47,47]
			  },
			  {
				name: "最少红灯",
				data: [50,52,52,53,54,54,54,55,53,54,54,54,54,55,53,54,52,52,52,54,54,54,54,55,53,53,53,53,53,53,52,51,52,53,49,50,50,50,49,49,47,48]
			  },
			  {
				name: "西乡大道",
				data: [52,55,55,57,53,52,52,53,51,52,52,52,52,53,50,50,49,49,49,51,51,51,52,53,51,51,52,52,51,51,50,50,51,52,48,49,50,50,49,50,49,49]
			  }
            ]
          };
        this.chartData = JSON.parse(JSON.stringify(res));
      }, 500);
	  
	  uni.request({
	      url: 'http://192.168.31.184:8080/wayInfo', //仅为示例，并非真实接口地址。
	      success: (res) => {
	          this.chartData = res.data;
	      }
	  });
	  
    },
  }
};
</script>

<style scoped>
	
	.titleBar {
		width: 91%;
		height: 35px;
		margin: 0 auto;
		margin-top: 30px;
	}
	
	.selectDate {
		width: 120px;
		margin: 0 auto;
	}
	
	.label-box {
		background-color: white;
		width: 91%;
		height: 80%;
		margin: 0 auto;
	}
	
  /* 请根据实际需求修改父元素尺寸，组件自动识别宽高 */
  .charts-box {
    width: 100%;
    height: 300px;
	margin-top: 7px;
  }
</style>